var s = 10//提交按钮倒计时秒数
var count = null;
function timerRun(){
	s--;
	if(s == 0){
		window.clearInterval(count);
		$(".payBtnBox").show();
		$(".processing").hide();
	}
	
	}

$(function(){
	/*提交订单成功页*/
	$(".paymentTit li").bind('click',function(){
		var pIndex = $(this).index();
		$(".paymentTit li").removeClass("on");
		$(this).addClass("on");
		$(".paymenWrap").hide();
		$(".paymenWrap").eq(pIndex).show();
	});
	var paymentList = $(".paymentList");
	var paymentUsed= $(".paymentUsed");
	paymentList.find(".Payment").hover(function(){
		$(this).addClass("focus");
	},function(){
		$(this).removeClass("focus");
	});
	$(".payRecommend span").hover(function(){
	},function(){
		$(this).removeClass("focus");
	});
	function paymentChoose(pThis){
		var paymentIndex = pThis.attr("class").split("_")[1];
		var wrapIndex = pThis.find("b").attr("class").split("_")[1];
		var paymentPro = pThis.find("b").html();
		paymentUsed.eq(0).show();
		paymentUsed.eq(1).hide();
		$(".payOpenCon,.payRecommend").show();
		paymentUsed.find("span").removeClass().addClass("Payment payment_"+paymentIndex);
		paymentUsed.find("span").children("b").removeClass().addClass("payIcon p_"+wrapIndex).html(paymentPro);
		paymentList.find(".Payment").removeClass("on");
	}
	paymentList.find(".Payment").bind('click',function(){
		var $this=$(this);
		paymentChoose($this);
		$this.addClass("on");
		$this.parents(".paymentCon").hide();
	});
	$(".payRecommend span").bind('click',function(){
		paymentChoose($(this));
		$(".paymentTit li").removeClass("on");
		$(".paymentTit li").eq(0).addClass("on");
		$(".paymenWrap").hide();
		$(".paymenWrap").eq(0).show();
		paymentList.find(".payment_23").addClass("on");
	});
	$(".paymentOpen").bind('click',function(){
		$(".paymentCon").show();
		$(this).parent().hide();
		$(".payRecommend").hide();
	});
	
	$(".PaymentMore").bind('click',function(){
		$(this).hide();
		$(this).parent().css('height','auto');
	});
	
	$(".paySec-close,.pc-items a").bind('click',function(){
		$(".paySecPop,.popMask").hide();
	});
	//支付成功或失败弹层end
	
	$(".twoDimText").html("下载手机酒帝网<br>随时随地查物流");
	//发送短信验证码倒计时开始
	var time =60;
	var i=null;
	function getTimer(){
		time--;
		if(time==0){
			clearInterval(i);
			$(".qjwSubmit1").show();
			$(".qjwSubmit11").hide();
			time=59;
		}
		$(".qjwSubmit11 em").text(time);
		
	}
	
	//一键支付发送短信验证码
	$(".qjwSubmit1").bind('click',function(){
		var bankReservedPhoneObj = $("#bankReservedPhone");
		if(!fixedillVal(bankReservedPhoneObj)){
			return false;
		}
        $(this).hide();
		$(".qjwSubmit11").show();
	    i=setInterval(getTimer,1000);
		var bankReservedPhone = $("#bankReservedPhone").val();//银行预留手机号
		$.ajax({
			type:'post',
			data:{"mobile":bankReservedPhone},
			url:'/nowPay/getSmsCode.htm',
			dataType:'json',
			cache:false,
			success:function(data){
				
			}
		});
		
	});
	//发送短信验证码结束
	//协议弹窗
	$(".agreeBtn").bind('click',function(){
		$(".agreeWrap,.popMask").show();
	});
	$(".agreeWrap .title i").bind('click',function(){
		$(".agreeWrap,.popMask").hide();
	});
	$(".concur").bind('click',function(){
		$(".agreeWrap,.popMask").hide();
		$(".agreement").attr("checked","checked");
	});
	
	
	//一键支付首次支付，支付提交
	$("#nowpay_firstPaysub").bind('click',function(){
		
		
		var cardOwnerName = $("#cardOwnerName");//持卡人姓名
		var identifyCardNum = $("#identifyCardNum");//身份证号码
		var bankCardNum = $("#bankCardNum");//银行卡号码
		var limitedPeriod_year = $("#limitedPeriod_year")
		var limitedPeriod_month = $("#limitedPeriod_month");//有效期月份
		var cardVerificationCode = $("#cardVerificationCode");//信用卡背后三位数
		var bankReservedPhone = $("#bankReservedPhone");//银行预留手机号
		var mVerificationCode = $("#mVerificationCode");//短信验证码
		var agreement = $("#agreement");
		if(!fixedillVal(cardOwnerName)){
			cardOwnerName.focus();
			return false;
		}
		if(!fixedillVal(identifyCardNum)){
			identifyCardNum.focus();
			return false;
		}
		if(!fixedillVal(bankCardNum)){
			bankCardNum.focus();
			return false;
		}
		if(!fixedillVal(limitedPeriod_month)){
			limitedPeriod_month.focus();
			return false;
		}
		
		if(!fixedillVal(limitedPeriod_year)){
			limitedPeriod_year.focus();
			return false;
		}
		
		if(!fixedillVal(cardVerificationCode)){
			cardVerificationCode.focus();
			return false;
		}
		if(!fixedillVal(bankReservedPhone)){
			bankReservedPhone.focus();
			return false;
		}
		if(!fixedillVal(mVerificationCode)){
			mVerificationCode.focus();
			return false;
		}
		if(!fixedillVal(agreement)){
			agreement.focus();
			return false;
		}
		$(this).parent().hide();
		$(".processing").show();
		var count = window.setInterval("timerRun();", 1000);
		$(".paySecPop,.popMask").show();
		var cardOwnerName = $.trim($("#cardOwnerName").val());
		var identifyCardNum =$.trim($("#identifyCardNum").val());
		var bankCardNum = $.trim($("#bankCardNum").val());
		var limitedPeriod = $.trim($("#limitedPeriod_month").val() + $("#limitedPeriod_year").val());
		var cardVerificationCode = $.trim($("#cardVerificationCode").val());
		var bankReservedPhone = $.trim($("#bankReservedPhone").val());
		var mVerificationCode = $.trim($("#mVerificationCode").val());
		$.ajax({
			type:'post',
			data:{"cardOwnerName":cardOwnerName,"idCardNum":identifyCardNum,"bankCardNum":bankCardNum,"expireDate":limitedPeriod,"cvv2":cardVerificationCode,"mobile":bankReservedPhone,"smsCode":mVerificationCode},
			url:'/nowPay/firstPay.htm',
			dataType:'json',
			cache:false,
			success:function(data){
				if(data == null){
					$(".payBtnBox").show();
					$(".processing").hide();
					alert("支付失败")
				}else if(data.status == 1 ){
					var orderSn = data.ordersn;
					var orderAmt = data.mhtOrderAmt;
					var channel = data.channel;
					window.location.href="paySuccessStatus-" + orderSn + "," + orderAmt + "," + channel + ".htm";	
				}else if(data.status == 2 || data.status == 3){
					$(".payBtnBox").show();
					$(".processing").hide();
					alert("支付失败，请检查输入信息是否正确！")
					
				}else if(data.status == 4 || data.status == 5){
					$(".payBtnBox").show();
					$(".processing").hide();
					alert("支付出错：" + data.errMsg);
				}else if(data.status == 6){
					window.location.href = "http://login.jiuxian.com/login.htm";
				}
			}
		});
	});
	
	
	//一键支付，支付提交
	$("#nowpay_paysub").bind('click',function(){
		
		var bankReservedPhone = $("#bankReservedPhone");//银行预留手机号
		var mVerificationCode = $("#mVerificationCode");//短信验证码
		if(!(fixedillVal(bankReservedPhone) && fixedillVal(mVerificationCode))){
			return false;
		}
		$(this).parent().hide();
		$(".processing1").show();
		var count = window.setInterval("timerRun();", 1000);
		var bankReservedPhone = $("#bankReservedPhone").val();//银行预留手机号
		var mVerificationCode = $.trim($("#mVerificationCode").val());//短信验证码
		
		$.ajax({
			type:'post',
			data:{"mobile":bankReservedPhone,"smsCode":mVerificationCode},
			url:'/nowPay/pay.htm',
			dataType:'json',
			cache:false,
			success:function(data){
				if(data == null){
					$(".payBtnBox").show();
					$(".processing1").hide();
					alert("支付失败")
				}else if(data.status == 1 ){
					var orderSn = data.ordersn;
					var orderAmt = data.mhtOrderAmt;
					var channel = data.channel;
					window.location.href="paySuccessStatus-" + orderSn + "," + orderAmt + "," + channel + ".htm";
				}else if(data.status == 2 || data.status == 3){
					$(".payBtnBox").show();
					$(".processing1").hide();
					alert("支付失败，请检查输入信息是否正确！")
					
				}else if(data.status == 4 || data.status == 5){
					$(".payBtnBox").show();
					$(".processing1").hide();
					alert("支付出错：" + data.errMsg);
				}else if(data.status == 6){
					window.location.href = "http://login.jiuxian.com/login.htm";
				}
			}
		});
		
		
	});
	
	//一键支付表单校验
	
	 $(".paymentUsed input").bind("blur",function(){
		return fixedillVal($(this));
	});
	
	function fixedillVal(obj){
		var illegalRegExp = /[;\/<>\*"'\~=\+\^%\$&{}\\]+/g;   //特殊字符
		var mobilePhoneRegExp = /^1[3|4|5|7|8][0-9]{9}$/;	//手机
		var chineseRegExp =   /^[\u4e00-\u9fa5]+$/;        //名字
		var eng = /^[(\a-zA-Z )]+$/;                            //名字			
		var isIDCard1=/^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$/;  //15位身份证
		var isIDCard2=/^((1[1-5])|(2[1-3])|(3[1-7])|(4[1-6])|(5[0-4])|(6[1-5])|71|(8[12])|91)\d{4}((19\d{2}(0[13-9]|1[012])(0[1-9]|[12]\d|30))|(19\d{2}(0[13578]|1[02])31)|(19\d{2}02(0[1-9]|1\d|2[0-8]))|(19([13579][26]|[2468][048]|0[48])0229))\d{3}(\d|X|x)?$/;  //18位身份证
		var number = /^[0-9]+$/;                       //银行卡
		var number3 = /^[0-9]{3}$/;    
		var value = $.trim(obj.val()); 
		if(value == ""){
			if(obj.hasClass("required")){
				obj.parent().siblings(".errorTip").text("您输入的内容不能为空").show();
				return false;
			}else if(obj.hasClass("payagain_required")){
				$(".errorTip").text("您输入的内容不能为空").show();
				return false;
			}		
		}else{
			if(illegalRegExp.test(value)){
				obj.parent().siblings(".errorTip").text("您输入的内容含有特殊字符").show();
				return false;			
			}else{
				obj.parent().siblings(".errorTip").hide();
			}
			
			if(obj.hasClass("chinese") && !(chineseRegExp.test(value) || eng.test(value) )){
				obj.parent().siblings(".errorTip").text("请输入中文或英文").show();
				return false;
			}else if(obj.hasClass("mobilePhone") && !mobilePhoneRegExp.test(value)){
				obj.parent().siblings(".errorTip").text("请输入正确的手机号码").show();
				return false;
			}else if(obj.hasClass("number") && !number.test(value)){
				obj.parent().siblings(".errorTip").text("请输入正确的银行卡号").show();
				return false;
			}else if(obj.hasClass("number3") && !number3.test(value)){
				obj.parent().siblings(".errorTip").text("请输入正确的三位数字").show();
				return false;
			}else if(obj.hasClass("isIDCard")){
				var valIDCar =  $.trim($(".isIDCard").val());
					len = valIDCar.length;
				if(len === 15){
					if(!isIDCard1.test(value)){
						obj.parent().siblings(".errorTip").text("请输入正确的身份证号码").show();
						return false;
					}
				}else if(len === 18){
					if(!isIDCard2.test(value)){
						obj.parent().siblings(".errorTip").text("请输入正确的身份证号码").show();
						return false;
					}
				}else{
					obj.parent().siblings(".errorTip").text("请输入正确的身份证号码").show();
					return false;
				}
			}else if(obj.hasClass("limitedPeriod")){
				if(value == "00"){
					obj.parent().siblings(".errorTip").text("请选择卡有效期").show();
					return false;
				}
			}
		}
		if(obj.hasClass("agreementClass")){
			if($(".agreementClass").attr("checked") != "checked"){
				alert("请同意协议!!")
				return false;
			}
		}
		obj.siblings(".errorTip").hide();
		return true;
	}
	function iptForm(){		
		$(".inputForm").bind("blur",function(){
			var _this = $(this);
			fixedillVal(_this);		
		});	
	}
	//协议弹窗
	$("#lookAgreement").bind('click',function(){
		$(".agreeWrap,.popMask").show();
	});
	$(".agreeWrap .title i").bind('click',function(){
		$(".agreeWrap,.popMask").hide();
	});
	$(".concur").bind('click',function(){
		$(".agreeWrap,.popMask").hide();
	});
	//卡验证码获取焦点
	$(".formBox .form4,.backNum").click(function(e) {
		$(".backNum").hide();	
		$(".formBox .form4").focus();		
	});
	
	$(".formBox .form4").bind("blur",function(){
		 $(".backNum").show();				 
	});

	
	$(".tigger").bind('click',function(){
		 var $tigger = $(this);
		 $.showAlert({"content":"解除成功后，将不能使用该卡快捷支付，确定解绑吗？", "type":"confirm","cancelShow":true, 
		    	"callback":function(){
		
					 var identifyCode = $tigger.attr("identifyCode");
					 if(identifyCode == ""){
					 	alert("解绑失败，绑定码为空，请联系客服");
						return false;
					 }
					 //var proxy_url = "/httpProxyAccess.htm?t="+new Date().getTime();target:act_request_url,
					 var act_request_url ="http://pay.jiuxian.com/nowPay/cancelBind.htm";
					 jQuery.ajax({
					 		type:'post',
							data:{"identifyCode":identifyCode},
							url:act_request_url,
							dataType:'json',
							cache:false,
							success:function(data){
								if(data == null){
									alert("解绑失败！");
									return;
								}
								if(data.status == 1){
									alert("解绑成功！");
									window.location.reload();
								}else{
									alert("解绑失败！");
								}
							}
					 
					 	});
		    
		    	}
		 
		    })
		 
		});	
			
})